/*
 * @(#)PatientIdentityClientITCase.java
 * Date 2013-02-21
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.pix.client;

import us.hornerscorners.lamppost.pix.client.PixManagerClient;
import java.net.URL;

import org.hl7.v3.CS;
import org.hl7.v3.EnFamily;
import org.hl7.v3.EnGiven;
import org.hl7.v3.II;
import org.hl7.v3.PN;
import org.hl7.v3.PRPAMT201301UV02OtherIDs;
import org.hl7.v3.PRPAMT201301UV02Patient;
import org.hl7.v3.PRPAMT201301UV02Person;

import org.junit.Test;

import us.hornerscorners.lamppost.config.EndpointConfig;

import us.hornerscorners.lamppost.hl7v3common.utils.HL7Utils;


/**
 *
 * @author jim
 */
public class PatientIdentityClientITCase {

    /**
     * Method description
     *
     *
     * @throws Exception
     */
    @Test
    public void addPatientRecordTest() throws Exception {

        URL url = new URL("http://localhost:37080/axis2/services/pixmgr");
        EndpointConfig config = new EndpointConfig(url, 2500, 5000);
        PixManagerClient client = new PixManagerClient(config);

        PRPAMT201301UV02Patient patient = new PRPAMT201301UV02Patient();

        patient.getClassCode().add("PAT");

        CS statusCode = new CS();

        statusCode.setCode("active");
        patient.setStatusCode(statusCode);

        II edipi = new II();

        edipi.setAssigningAuthorityName("USDOD");
        edipi.setRoot("2.16.840.1.113883.3.42.10001.100001.12");
        patient.getId().add(edipi);

        PRPAMT201301UV02Person person = new PRPAMT201301UV02Person();
        PN name = new PN();

        name.getUse().add("L");

        EnGiven givenName = HL7Utils.hl7Factory.createEnGiven();

        givenName.getContent().add("Fred");
        name.getContent().add(HL7Utils.hl7Factory.createENGiven(givenName));

        EnFamily familyName = HL7Utils.hl7Factory.createEnFamily();

        familyName.getContent().add("Flintstone");

        name.getContent().add(HL7Utils.hl7Factory.createENFamily(familyName));

        person.getName().add(name);

        PRPAMT201301UV02OtherIDs otherOrgId = new PRPAMT201301UV02OtherIDs();
        II otherId = new II();

        otherId.setExtension("100002");
        otherId.setAssigningAuthorityName("JIM");
        otherId.setRoot("1.2.3.4");
        otherOrgId.getId().add(otherId);
        person.getAsOtherIDs().add(otherOrgId);

        patient.setPatientPerson(
            HL7Utils.hl7Factory.createPRPAMT201301UV02PatientPatientPerson(
                person));

        client.addPatientRecord(patient);
    }
}
